package servlet;

import Day528.DB;
import bean.Student;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet(name = "updateById", value = "/updateById")
public class updateById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id = request.getParameter("id");
        String sql = "select from student where id=?";
        ResultSet rs = null  ;
        try {
            rs = DB.query(sql, id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            rs.next();
            int id1 = rs.getInt("id");
            String name = rs.getString("name");
            String sex = rs.getString("sex");
            Student stu = new Student(id1,name,sex);
            request.setAttribute("student",stu);
            request.getRequestDispatcher("/edit.jsp" ).forward(request,response);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
